import jwt
import hashlib
from mydjango import settings
import redis




def make_token(userinfo):
    token = jwt.encode(userinfo, settings.SECRET_KEY, algorithm='HS256').decode()
    return token

def chack_token(token):
    userinfo = jwt.decode(token, settings.SECRET_KEY, algorithms=['HS256'])

    return userinfo

r0 = redis.Redis(host='192.168.1.65', port=6379, db=0, decode_responses=True)


# 重写make_password方法使用md5进行加密
def make_password(mypass):
    md5 = hashlib.md5()

    # 定义加密对象
    sign_str = mypass
    # 转码
    sign_utf8 = str(sign_str).encode(encoding='utf-8')
    # 加密
    md5.update(sign_utf8)
    # 生成密文
    md5_server = md5.hexdigest()

    return md5_server




